package com.edu.imau.ManageUserInformation;

import com.edu.imau.ParkingDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/add")
public class UserAddServlet extends HttpServlet {
    private ParkingDao dao = new ParkingDao();
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //1 处理参数
        String id_str = request.getParameter("id");
        String code =request.getParameter("code");
        String number =request.getParameter("number");
        String name =request.getParameter("name");
        String carcode =request.getParameter("carcode");
        String indate =request.getParameter("indate");
        String outdate =request.getParameter("outdate");
//        int id=Integer.parseInt(id_str);
        //2 调用model
        if(id_str == null||id_str.equals("")){
            User user = new User(-1,code,number,name,carcode,indate,outdate);
            dao.addUser(user);
        }else{
            User user = new User(Integer.parseInt(id_str),code,number,name,carcode,indate,outdate);
            dao.updateUser(user);
        }
        //3 数据交给View
        response.sendRedirect("user.jsp");
    }
}
